package com.bwie.system.controller;

import com.bwie.common.domain.SysFeature;
import com.bwie.common.domain.SysOpeningHours;
import com.bwie.common.domain.SysShop;
import com.bwie.common.domain.request.SysShopRequest;
import com.bwie.common.domain.vo.SysShopVo;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.system.service.SysShopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: SysShop
 * @Description:
 * @Author: 平安
 * @Date: 2024/4/25 10:37:50
 */
@RestController
public class SysShopController {

    @Autowired
    private SysShopService sysShopService;


    @PostMapping("/shopList")
    public Result<PageResult<SysShop>> shopList(@RequestBody SysShopRequest sysShopRequest){
        PageHelper.startPage(sysShopRequest.getPageNum(), sysShopRequest.getPageSize());
        List<SysShop> sysShopList = sysShopService.shopList(sysShopRequest);
        PageInfo<SysShop> info = new PageInfo<>(sysShopList);
        return Result.success(PageResult.toPageResult(info.getTotal(), sysShopList));
    }

    @GetMapping("/featureList/{shopId}")
    public Result<List<SysFeature>> featureList (@PathVariable Integer shopId){
        return Result.success(sysShopService.featureList(shopId));
    }

    @GetMapping("/openingHoursList/{shopId}")
    public Result<List<SysOpeningHours>> openingHoursList (@PathVariable Integer shopId){
        return Result.success(sysShopService.openingHours(shopId));
    }

    @PostMapping("/upload")
    public Result upload(@RequestParam("file") MultipartFile multipartFile){
        return sysShopService.upload(multipartFile);
    }

    @PostMapping("/addShop")
    public Result addShop(@RequestBody SysShopVo sysShopVo){
        return sysShopService.addShop(sysShopVo);
    }

}
